// pages/home-page/customer-analysis/customerAnalysis.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CDNPATH: app.globalData.CDNPATH,
    list: [],
    code: '',
    customerId: '',
    page: {
      currentPage: 0,
      pageSize: 10
    },
    typeList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 安卓
    wx.setBackgroundColor({
      backgroundColor: '#0061E3',
    })
    // 兼容ios
    wx.setBackgroundColor({
      backgroundColorTop: '#0061E3',
      backgroundColorBottom: '#F3F6FA',
    })  
    this.setData({
      customerId: options.id
    })
    this.getTypeList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getTypeList: function () {
    app.api.post({
      url: 'product_adaptPeople'
    }).then(res => {
      this.setData({
        typeList: res,
        code: res[0].code
      })
      this.getProductList()
    })
  },
  getProductList: function (e) {
    const { code, customerId } = this.data
    app.api.post({
      url: 'product_recommend_productRecommend',
      data: { adaptPeople: code, customerId }
    }).then(res => {
      this.setData({
        list: res
      })
    })
  },
  createProject: function (e) {
    const { customerId } = this.data
    const { id: productId, code: productCode, packageId } = e.currentTarget.dataset
    app.api.post({
      url: 'customer_stage_add',
      data: {
        customerId,
        productId,
        stage: 'proposal' // appointment 约访训练，interview 面谈训练 
      }
    }).then(res => {
      wx.navigateTo({
        url: `/pages/home-page/project/project?customerId=${customerId}&productId=${productId}&productCode=${productCode}&packageId=${packageId}`
      })
    })
  },
  tapType: function (e) {
    const { code } = e.currentTarget.dataset
    this.setData({
      code,
    })
    this.getProductList()
  },
})